﻿namespace ComponentSystem
{
	/// <summary>
	/// 生成ID
	/// </summary>
	public static class IdGenerater
	{
		/// <summary>
		/// 应用ID
		/// </summary>
		public static long AppId { private get; set; }

		/// <summary>
		/// 值
		/// </summary>
		private static ushort value;

		/// <summary>
		/// 生成ID
		/// </summary>
		/// <returns></returns>
		public static long GenerateId()
		{
			long time = TimeHelper.ClientNowSeconds();

			return (AppId << 48) + (time << 16) + ++value;
		}

		/// <summary>
		/// 获取应用ID
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static int GetAppIdFromId(long id)
		{
			return (int)(id >> 48);
		}
	}
}